﻿using System;
using System.Collections.Generic; 
using System.Text;
using System.Data; 
using System.Data.SqlClient;
using MyHotel_DTO;
using MyHotel_Common;

namespace MyHotel_DAO
{
    public class ThamSoDAO : DAO
    {
        protected override object createObjectFromDatarow(DataRow row)
        {
            ThamSo thamso = new ThamSo();
            thamso.MaThamSo = Convert.ToInt32(row["MaThamSo"]);
            thamso.SokhachToiDa = Convert.ToInt32(row["SoKhachToiDa1Phong"]);
            thamso.TylePhuThu = float.Parse(row["TyLePhuThu"].ToString());
            return thamso;
        }
        
        public ThamSo getThamSo()
        {
            string nameProc = "sp_thamso"; 
            DataTable dt = DataProvider.executeStoreProcedureQuery(nameProc, null);
            ThamSo thamso = new ThamSo();
            if(dt.Rows.Count != 0)
                thamso = (ThamSo)createObjectFromDatarow(dt.Rows[0]);
            return thamso;
        } 
        public bool themThamSo(ThamSo thamso)
        {
            string nameProc = "them_thamso";
            SqlParameter[] para = new SqlParameter[2];
            para[0] = new SqlParameter("@sokhachtoida", thamso.SokhachToiDa);
            para[1] = new SqlParameter("@tilephuthu", thamso.TylePhuThu); 
            int n = DataProvider.executeStoreProcedureNonQuery(nameProc, para); 
            return (n == 1); 
        }
    }
}
